package com.wawayaya.bookreader.worddict;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by wang_qian on 2015/11/5.
 */
public class EnWordDictDescData implements Parcelable {

    public int m_iviewId = -1;

    public int m_ibookid = -1;
    public int m_inetid = -1;

    public String mClickWord = null;
    public String mBaseWord = null;

    public String mPhrases = null;
    public int     mPhraseIndex = -1;

    public String[] m_ssduyin = null;
    public EnWordDictData[]  mDicts = null;


    public void clear() {
        if(null != mDicts) {
            for(EnWordDictData item : mDicts) {
                if(null != item) {
                    item.clear();
                }
            }
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(m_iviewId);
        dest.writeInt(m_ibookid);
        dest.writeInt(m_inetid);
        dest.writeString(mClickWord);
        dest.writeString(mBaseWord);

        dest.writeString(mPhrases);
        dest.writeInt(mPhraseIndex);

        if (mDicts == null) {
            dest.writeInt(0);
        } else {
            dest.writeInt(mDicts.length);
            dest.writeTypedArray(mDicts, 0);
        }
    }

    public static final Parcelable.Creator<EnWordDictDescData> CREATOR = new Creator<EnWordDictDescData>(){
        @Override
        public EnWordDictDescData createFromParcel(Parcel source) {
            EnWordDictDescData pwdd = new EnWordDictDescData();
            pwdd.m_iviewId = source.readInt();

            pwdd.m_ibookid = source.readInt();
            pwdd.m_inetid = source.readInt();
            pwdd.mClickWord = source.readString();
            pwdd.mBaseWord = source.readString();
            pwdd.mPhrases = source.readString();
            pwdd.mPhraseIndex = source.readInt();

            int lenght = source.readInt();
            if(lenght <= 0) {
                pwdd.mDicts = null;
            }
            else{
                pwdd.mDicts = new EnWordDictData[lenght];
                source.readTypedArray(pwdd.mDicts, EnWordDictData.CREATOR);
            }
            return pwdd;
        }

        @Override
        public EnWordDictDescData[] newArray(int size) {
            return new EnWordDictDescData[size];
        }
    };

    public static class EnWordDictData implements Parcelable {
        public int  mDictId = -1;
        public String mDictName;
        public String mDictType;
        public String mYinBiao;

        public EnWordCiXingData[]  mCiXings = null;

        public void clear() {
            if(null != mCiXings) {
                for(EnWordCiXingData item : mCiXings) {
                    if(null != item) {
                        item.clear();
                    }
                }
            }
        }


        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(mDictId);
            dest.writeString(mDictName);
            dest.writeString(mDictType);
            dest.writeString(mYinBiao);

            if (mCiXings == null) {
                dest.writeInt(0);
            } else {
                dest.writeInt(mCiXings.length);
                dest.writeTypedArray(mCiXings, 0);
            }

        }

        public static final Parcelable.Creator<EnWordDictData> CREATOR = new Creator<EnWordDictData>(){
            @Override
            public EnWordDictData createFromParcel(Parcel source) {
                EnWordDictData wdij = new EnWordDictData();
                wdij.mDictId = source.readInt();
                wdij.mDictName = source.readString();
                wdij.mDictType = source.readString();
                wdij.mYinBiao = source.readString();

                int lenght = source.readInt();
                if(lenght <= 0) {
                    wdij.mCiXings = null;
                }
                else{
                    wdij.mCiXings = new EnWordCiXingData[lenght];
                    source.readTypedArray(wdij.mCiXings, EnWordCiXingData.CREATOR);
                }

                return wdij;
            }

            @Override
            public EnWordDictData[] newArray(int size) {
                return new EnWordDictData[size];
            }
        };
    }

    public static class EnWordCiXingData implements Parcelable {
        public int        mCiXingId = -1;
        public String mCXdecs;
        public String mFuShu;

        public EnWordJieshiData[]  mJieShis = null;

        public void clear() {
            if(null != mJieShis) {
                for(EnWordJieshiData item : mJieShis) {
                    if(null != item) {
                        item.clear();
                    }
                }
            }
        }


        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(mCiXingId);
            dest.writeString(mCXdecs);
            dest.writeString(mFuShu);
            if (mJieShis == null) {
                dest.writeInt(0);
            } else {
                dest.writeInt(mJieShis.length);
                dest.writeTypedArray(mJieShis, 0);
            }
        }

        public static final Parcelable.Creator<EnWordCiXingData> CREATOR = new Creator<EnWordCiXingData>(){

            @Override
            public EnWordCiXingData createFromParcel(Parcel source) {
                EnWordCiXingData wdij = new EnWordCiXingData();
                wdij.mCiXingId = source.readInt();
                wdij.mCXdecs = source.readString();
                wdij.mFuShu = source.readString();

                int lenght = source.readInt();
                if(lenght <= 0) {
                    wdij.mJieShis = null;
                }
                else{
                    wdij.mJieShis = new EnWordJieshiData[lenght];
                    source.readTypedArray(wdij.mJieShis, EnWordJieshiData.CREATOR);
                }

                return wdij;
            }

            @Override
            public EnWordCiXingData[] newArray(int size) {
                return new EnWordCiXingData[size];
            }
        };
    }

    public static class EnWordJieshiData implements Parcelable {


        public String mShiYi = null;
        //public EnParcelableCizu[] mCiZus = null;
        public EnParcelableCizu[] mLiJus = null;

        public void clear() {

        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(mShiYi);
  /*          if (mCiZus == null) {
                dest.writeInt(0);
            } else {
                dest.writeInt(mCiZus.length);
                dest.writeTypedArray(mCiZus, 0);
            }*/

            if (mLiJus == null) {
                dest.writeInt(0);
            } else {
                dest.writeInt(mLiJus.length);
                dest.writeTypedArray(mLiJus, 0);
            }

        }


        public static final Parcelable.Creator<EnWordJieshiData> CREATOR = new Creator<EnWordJieshiData>(){

            @Override
            public EnWordJieshiData createFromParcel(Parcel source) {
                EnWordJieshiData wdij = new EnWordJieshiData();
                wdij.mShiYi = source.readString();
/*                int lenght = source.readInt();
                if(lenght <= 0) {
                    wdij.mCiZus = null;
                }
                else{
                    wdij.mCiZus = new EnParcelableCizu[lenght];
                    source.readTypedArray(wdij.mCiZus, EnParcelableCizu.CREATOR);
                }*/
                int lenght = source.readInt();
                if(lenght <= 0) {
                    wdij.mLiJus = null;
                }
                else{
                    wdij.mLiJus = new EnParcelableCizu[lenght];
                    source.readTypedArray(wdij.mLiJus, EnParcelableCizu.CREATOR);
                }
                return wdij;
            }

            @Override
            public EnWordJieshiData[] newArray(int size) {
                return new EnWordJieshiData[size];
            }

        };
    }

    public static class EnParcelableCizu implements Parcelable {

        public String mLiJu;
        public String mLiJuJieShi;

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(mLiJu);
            dest.writeString(mLiJuJieShi);
        }

        public static final Parcelable.Creator<EnParcelableCizu> CREATOR = new Creator<EnParcelableCizu>() {

            @Override
            public EnParcelableCizu createFromParcel(Parcel source) {
                EnParcelableCizu pc = new EnParcelableCizu();
                pc.mLiJu = source.readString();
                pc.mLiJuJieShi = source.readString();
                return pc;
            }

            @Override
            public EnParcelableCizu[] newArray(int size) {
                return new EnParcelableCizu[size];
            }

        };

    }






}
